package edu.sctu.zcy.month201505.day20150517;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 * Created by user24 on 2015/5/17.
 */
public class CollectionSort {

    public void sortsCollection(){
        List<Integer> integers = new ArrayList<Integer>();

        Random random = new Random();

        for (int i = 0; i < 10; i++) {

            Integer k;
            do {

                k = random.nextInt(100);

            } while (integers.contains(k));

            integers.add(k);
            System.out.println("成功添加整数：" + k);

        }


            System.out.println("----------排序前--------------");
            for (Integer integer : integers){

                System.out.println(integer);

            }

          Collections.sort(integers);

            System.out.println("---------------排序后------------------");

        for (Integer integer : integers){

            System.out.println(integer);

        }
    }

    public void sort2(){

        List<String> stringslist = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            stringslist.add("leoven"+i);
        }

        System.out.println("-----排序前------");
        for(String s : stringslist){
            System.out.println("元素："+s);

        }
        Collections.sort(stringslist);
        System.out.println("-------排序后--------");
        for(String s : stringslist){
            System.out.println("元素："+s);

        }
    }

    public void sort3(){
        List<edu.sctu.zcy.month201505.day20150514.Student> list = new ArrayList<>();

        list.add(new edu.sctu.zcy.month201505.day20150514.Student(1+"","yucy"));
        list.add(new edu.sctu.zcy.month201505.day20150514.Student(5+"","zcy"));
        list.add(new edu.sctu.zcy.month201505.day20150514.Student(3+"","sfd"));

        System.out.println("-----排序前------");
        for(edu.sctu.zcy.month201505.day20150514.Student s : list){
            System.out.println("学生："+s.name);

        }

       Collections.sort(list);

        System.out.println("-------排序后--------");
        for(edu.sctu.zcy.month201505.day20150514.Student s : list){
            System.out.println("元素："+s.name);

        }
        Collections.sort(list,new ComparetorTest());
        System.out.println("-----按姓名排序后------");
        for(edu.sctu.zcy.month201505.day20150514.Student s : list){
            System.out.println("元素："+s.name);

        }



    }

    public static void main(String[] args) {
        CollectionSort collectionSort = new CollectionSort();

        collectionSort.sortsCollection();
        collectionSort.sort2();
        collectionSort.sort3();
    }
}
